package cn.wolfcode.service.impl;

import cn.wolfcode.domain.BalanceDetail;
import cn.wolfcode.mapper.BalanceDetailMapper;
import cn.wolfcode.service.IBalanceDetailService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.imageio.plugins.wbmp.WBMPImageReader;

import java.math.BigDecimal;
import java.util.List;

public class BalanceDetailServiceImpl extends ServiceImpl<BalanceDetailMapper, BalanceDetail> implements IBalanceDetailService {

    /**
     * 支付记录
     * @param walletId  钱包ID
     * @param info      信息
     * @param payMoney  金额
     */
    @Override
    public void payInfo(Long walletId, String info, BigDecimal payMoney) {
        BalanceDetail balanceDetail = new BalanceDetail();
        balanceDetail.setWalletId(walletId);
        balanceDetail.setInfo(info);
        balanceDetail.setMoney(payMoney);
        balanceDetail.setType(BalanceDetail.BALANCE_DETAIL_TYPE_OUT);

        save(balanceDetail);
    }

    /**
     * 退款记录
     * @param detail        针对那条记录进行退款
     * @param refundInfo    退款信息
     */
    @Override
    public void refundInfo(BalanceDetail detail, String refundInfo) {
        BalanceDetail balanceDetail = new BalanceDetail();
        balanceDetail.setRefundId(detail.getId());
        balanceDetail.setType(BalanceDetail.BALANCE_DETAIL_TYPE_REFUND);
        balanceDetail.setMoney(detail.getMoney());
        balanceDetail.setInfo(refundInfo);
        balanceDetail.setWalletId(detail.getWalletId());

        save(balanceDetail);
    }

    // 根据钱包ID查询所有的信息
    @Override
    public List<BalanceDetail> listByWalletId(Long userWalletId) {

        LambdaUpdateWrapper<BalanceDetail> wrapper = Wrappers.lambdaUpdate(BalanceDetail.class).eq(BalanceDetail::getWalletId, userWalletId);

        return list(wrapper);
    }
}
